import threading
import multiprocessing
import time

def fibonacci(n):
    if n <= 1:
        return n
    else:
        return fibonacci(n-1) + fibonacci(n-2)

if __name__ == "__main__":
    start_time = time.time()

    # 多线程
    threads = []
    for _ in range(5):
        t = threading.Thread(target=fibonacci, args=(35,))
        threads.append(t)
        t.start()

    for t in threads:
        t.join()

    end_time = time.time()
    print(f"多线程执行时间：{end_time - start_time} 秒")

    # 多进程
    start_time = time.time()

    processes = []
    for _ in range(5):
        p = multiprocessing.Process(target=fibonacci, args=(35,))
        processes.append(p)
        p.start()

    for p in processes:
        p.join()

    end_time = time.time()
    print(f"多进程执行时间：{end_time - start_time} 秒")

    # 普通方法
    start_time = time.time()

    for _ in range(5):
        fibonacci(35)

    end_time = time.time()
    print(f"普通方法执行时间：{end_time - start_time} 秒")
